home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Linked List Template Classes / Linked Lists Ä.sit / Linked Lists ƒ / source code / SimpleWindowClass.cp < prev    next >
Text File  |  1995-03-02  |  2KB  |  87 lines

  1. #include <stdlib.h>
  2. #include "SimpleWindowClass.h"
  3.  
  4. void    SimpleWindowClass::CreateWindow(short windowNumber, short resID)
  5. {
  6.     //    Allocate memory for window record on our own, then create new window
  7.     
  8.     theWindow=(WindowPtr) NewPtr(sizeof (WindowRecord));
  9.     theWindow=GetNewWindow(resID, theWindow, (WindowPtr) -1L);
  10.     if (!theWindow)
  11.         exit(1);
  12.  
  13.  
  14.     //    Convert the window number passed to us into a string and get its width in
  15.     //    pixels, as well as the "This window..." width
  16.         
  17.     NumToString(windowNumber, sWindowNumber);
  18.     GetIndString(sThisWindow, 128, 1);
  19.     numWidth=StringWidth(sWindowNumber);
  20.     titleWidth=StringWidth(sThisWindow);
  21.     
  22.     
  23.     
  24.     //    Determine height of current font, to be used when centering text later
  25.     
  26.     FontInfo    sysFont;
  27.     
  28.     GetFontInfo(&sysFont);
  29.     fontHeight=sysFont.ascent+sysFont.descent;
  30.     
  31.     
  32.     
  33.     //    Show the window (not really necessary because resource is set to automatically show it
  34.     
  35.     SetPort(theWindow);
  36.     ShowWindow(theWindow);
  37. }
  38.  
  39. SimpleWindowClass::~SimpleWindowClass()
  40. {
  41.     //    Remove window from screen and QuickDraw's window list, then dispose of pointer 
  42.  
  43.     CloseWindow(theWindow);
  44.     DisposePtr((Ptr) theWindow);
  45. }
  46.  
  47. void    SimpleWindowClass::UpdateWindow()
  48. {
  49.     GrafPtr    oldPort;
  50.     
  51.     GetPort(&oldPort);
  52.     SetPort(theWindow);
  53.     
  54.     BeginUpdate(theWindow);
  55.     EraseRect(&theWindow->portRect);
  56.     DrawWindowNumber();
  57.     EndUpdate(theWindow);
  58.     
  59.     SetPort(oldPort);
  60. }
  61.  
  62. void    SimpleWindowClass::ActivateWindow(Boolean activate)
  63. {
  64.     if (activate)
  65.         SetPort(theWindow);
  66. }
  67.  
  68. void    SimpleWindowClass::DrawWindowNumber()
  69. {
  70.     //    Calculate horizontal and vertical centers to center the strings in the window
  71.     
  72.     short hCenter=(theWindow->portRect.right-theWindow->portRect.left)/2;
  73.     short vCenter=(theWindow->portRect.bottom-theWindow->portRect.top)/2;
  74.     
  75.     MoveTo(hCenter-(titleWidth/2), vCenter-fontHeight/2);
  76.     DrawString(sThisWindow);
  77.     MoveTo(hCenter-(numWidth/2), vCenter+fontHeight/2);
  78.     DrawString(sWindowNumber);
  79. }
  80.  
  81. void    SimpleWindowClass::Drag(Point where)
  82. {
  83.     RgnHandle greyRgn;
  84.     
  85.     greyRgn=GetGrayRgn();
  86.     DragWindow(theWindow, where, &(**greyRgn).rgnBBox);
  87. }